### Layout Module Install File - Form Processing Source: https://github.com/appstateess/canopy/blob/master/docs/Module_Development.txt Illustrates how an install file can process form data to gather site information, such as the site name and theme. This example shows adding template processing to the content array. ```php $content[] = PHPWS_Template::process($template, 'layout', 'setup.tpl'); ``` -------------------------------- ### Basic Cache Usage Example Source: https://github.com/appstateess/canopy/blob/master/docs/Cache_Lite.txt Demonstrates how to get, save, and display cached content. If the cache is empty or expired, it fetches the content the hard way and saves it. ```php $key = 'myModsContent'; $lifetime = 600; // number of seconds until cache refresh // default is set in CACHE_LIFETIME in the // config/core/config.php file // 600 seconds = 10 minutes $content = PHPWS_Cache::get($key, $lifetime); if (empty($content)) { $content = getContentTheHardWay(); PHPWS_Cache::save($key, $content); } Layout::add($content); ``` -------------------------------- ### Template File Example Source: https://github.com/appstateess/canopy/blob/master/docs/template.txt An example of a simple template file structure that uses placeholders for dynamic content. ```HTML
{HEADING}
{CONTENT} ``` -------------------------------- ### Install Grunt CLI and Development Dependencies Source: https://github.com/appstateess/canopy/blob/master/javascript/datepicker/README.md Install the Grunt command-line interface globally and then install the project's development dependencies using npm. ```bash npm install -g grunt-cli npm install ``` -------------------------------- ### Install npm Package Manager Source: https://github.com/appstateess/canopy/wiki/Installation-of-Canopy-for-ESS-Students Install npm, the Node Package Manager, which is often required for module development. This example is for Ubuntu. ```bash sudo apt-get install npm ``` -------------------------------- ### Complete Permissions File Example Source: https://github.com/appstateess/canopy/blob/master/docs/Module_Development.txt A complete example of a permissions file, indicating module permissioning is used, defining edit and delete sub-permissions, and enabling item permissions. ```php ``` -------------------------------- ### Install Fileinfo Extension using PECL Source: https://github.com/appstateess/canopy/blob/master/docs/Installing_FileInfo.txt Installs the Fileinfo PHP extension using the PECL package manager. ```bash sudo pecl install fileinfo ``` -------------------------------- ### Start Vagrant Environment Source: https://github.com/appstateess/canopy/blob/master/README.md Starts the Vagrant environment for Canopy. Ensure VirtualBox and Vagrant are installed before running this command. ```bash vagrant up ``` -------------------------------- ### Install PHP PEAR Source: https://github.com/appstateess/canopy/blob/master/docs/Installing_FileInfo.txt Installs the PHP PEAR package manager, which is necessary for installing PHP extensions using PECL. ```bash sudo apt-get install php-pear ``` -------------------------------- ### Install Imagic Development Files Source: https://github.com/appstateess/canopy/blob/master/docs/Installing_FileInfo.txt Installs the development files for Imagic, which is believed to provide the necessary magic database file for Fileinfo. ```bash sudo apt-get install libmagic-dev ``` -------------------------------- ### Install PHP Development Files Source: https://github.com/appstateess/canopy/blob/master/docs/Installing_FileInfo.txt Installs the PHP development files, which are required for PECL to function correctly when installing extensions like Fileinfo. ```bash sudo apt-get install php5-dev ``` -------------------------------- ### CKEditor 4 Installation Check Source: https://github.com/appstateess/canopy/blob/master/javascript/ckeditor/README.md Use this URL to verify your CKEditor 4 installation by accessing its sample index page. ```html http:////samples/index.html ``` ```html http://www.example.com/ckeditor/samples/index.html ``` -------------------------------- ### Install Composer Dependencies Source: https://github.com/appstateess/canopy/wiki/Installation-of-Canopy-for-ESS-Students Install PHP dependencies using Composer within the Canopy directory. Ensure PHP and Composer are installed. ```bash composer install ``` -------------------------------- ### Install npm Dependencies and Build Theme Source: https://github.com/appstateess/canopy/blob/master/README.md Installs Node.js dependencies and builds the production assets for the default Bootstrap 4 theme. Run these commands from the bootstrap4-default/ directory. ```bash npm install npm run prod ``` -------------------------------- ### Test FFmpeg Installation Source: https://github.com/appstateess/canopy/blob/master/docs/FFmpeg_and_Filecabinet.txt This command tests if FFmpeg is installed correctly by creating a JPEG thumbnail from the first frame of a FLV video. Ensure FFmpeg is compiled with FLV support for this to work. ```bash ffmpeg -i movie.flv -an -s 340x240 -r 1 -vframes 1 -y -f mjpeg movie.jpg ``` -------------------------------- ### PHP Prompt Example Source: https://github.com/appstateess/canopy/blob/master/javascript/prompt/readme.txt This snippet demonstrates how to set up variables and call the `javascript('prompt', ...)` function to display a user prompt. Ensure all variables are properly escaped using `addslashes()` before passing them. ```php $vars['question'] = 'What would you like to name this?'; $vars['address'] = 'index.php?module=mymode&command=change_name'; $vars['answer'] = 'Type the name here...'; $vars['value_name'] = 'new_name'; $vars['link'] = 'Click on me to name this'; $vars['type'] = 'link'; // or button $vars['class'] = 'css-class'; $vars['title'] = 'Hover text'; echo javascript('prompt', $vars); ``` -------------------------------- ### Initialize DateTimePicker with Options Source: https://github.com/appstateess/canopy/blob/master/javascript/datetimepicker/index.html Initializes the DateTimePicker with specific options for day of week start, language, disabled dates, and start date. ```javascript $('#datetimepicker').datetimepicker({ dayOfWeekStart : 1, lang:'en', disabledDates:['1986/01/08','1986/01/09','1986/01/10'], startDate: '1986/01/05' }); ``` -------------------------------- ### Block Module SmartTag Example Source: https://github.com/appstateess/canopy/blob/master/docs/SmartTags.txt An example of a SmartTag for the 'block' module, specifying the function 'view' and an ID '1'. If no default function is set, the function name must be explicitly provided. ```text [block:view:1] ``` -------------------------------- ### Instantiate Version Object Source: https://github.com/appstateess/canopy/blob/master/docs/Version.txt Create a Version object using the module name and the version ID obtained from GET parameters. ```php $version = & new Version('my_mod', $_GET['version_id']); ``` -------------------------------- ### Toggle Tag Example Source: https://github.com/appstateess/canopy/blob/master/docs/DB_Pager.txt Example of using the {TOGGLE} tag within a table row for dynamic display. ```html {TITLE} ``` -------------------------------- ### Build Docker Images Source: https://github.com/appstateess/canopy/wiki/Installation-of-Canopy-for-ESS-Students Build the Docker images for Canopy. Ensure Docker and Docker Compose are installed and configured. ```bash docker-compose build ``` -------------------------------- ### Start Docker Containers Source: https://github.com/appstateess/canopy/wiki/Installation-of-Canopy-for-ESS-Students Start the Canopy Docker containers in detached mode. This command needs to be run every time you start your machine. ```bash docker-compose up -d ``` -------------------------------- ### PHP Website Test File Setup Source: https://github.com/appstateess/canopy/blob/master/docs/test.php.txt This snippet sets up the environment for testing PHPWebsite functionality. It configures encoding, error reporting, includes core configuration and defines, and sets the timezone. ```php ``` -------------------------------- ### Module Dependency XML Example Source: https://github.com/appstateess/canopy/blob/master/docs/Module_Development.txt Defines the modules and versions required for a specific module to function correctly. Save this file as dependency.xml in your module's boost directory. ```xml comments Comments 0.2.5 http://phpwebsite.appstate.edu/downloads/modules/comments ``` -------------------------------- ### Get Version List Source: https://github.com/appstateess/canopy/blob/master/docs/Version.txt Retrieve the list of versions using the getList() method. ```php $content = $restore->getList(); Layout::add($content); ``` -------------------------------- ### Initialization Function Source: https://github.com/appstateess/canopy/blob/master/javascript/ckeditor/plugins/wsc/dialogs/ciframe.html Initializes the dialog by setting up an interval to send data to the master and starting the post message listener. ```javascript function onLoad() { interval = window.setInterval( sendData2Master, 100 ); listenPostMessage(); } ``` -------------------------------- ### Comment User Class Example Source: https://github.com/appstateess/canopy/blob/master/docs/Demographics.txt An example of a custom user class extending Demographics_User, showing a mix of default, custom, and module-specific variables. ```php class Comment_User extends Demographics_User { var $signature = NULL; // newly created field var $comments_made = 0; // not part of demographics var $joined_date = 0; // copied from user class var $avatar = NULL; // newly created field var $contact_email = NULL; // default demographics field var $website = NULL; // default demographics field var $location = NULL; // not part of demographics var $locked = 0; // using a second table with demographics var $_table = 'comments_users'; ... ``` -------------------------------- ### Blog Module SQL Table Creation Source: https://github.com/appstateess/canopy/blob/master/docs/Module_Development.txt Defines the SQL table structure for storing blog entries, including fields for ID, title, content, author, and dates. This example is for the Blog module's install.sql file. ```sql CREATE TABLE blog_entries ( id INT NOT NULL, key_id INT NOT NULL, title VARCHAR( 60 ) NOT NULL , summary TEXT NULL, entry TEXT NOT NULL, author_id INT NOT NULL default '0', author varchar(50) NOT NULL default '', create_date INT NOT NULL , allow_comments SMALLINT NOT NULL default '0', approved INT NOT NULL default '0', allow_anon SMALLINT NOT NULL default '0', PRIMARY KEY ( id ) ); CREATE INDEX blogentries_idx on blog_entries(key_id); ``` -------------------------------- ### Retrieve Version Data as Array Source: https://github.com/appstateess/canopy/blob/master/docs/Version.txt Get all data associated with the current version as an array. ```php $my_items_data = $version->getSource(); ``` -------------------------------- ### PHP Batch Processing Example Source: https://github.com/appstateess/canopy/blob/master/docs/Batch.txt This snippet demonstrates the basic usage of the PHPWS_Core Batch class for managing batch operations. It includes initialization, setting batch parameters, loading existing batch data, processing records, and handling completion. ```PHP clear(); // Total number of records $batches->setTotalItems($total_items); // Number of records to parse each iteration $batches->setBatchSet($batch_number); // Gets the batch number from the url and loads internal info if (!$batches->load()) { exit('Batch was previously run.'); } $start = $batches->getStart(); $limit = $batches->getLimit(); $db = new PHPWS_DB('some_table'); $db->setLimit($limit, $start); test($db->select()); // Shows a simple completion graph echo $batch->getGraph(); // We are done with this batch $batch->completeBatch(); if ($batch->isFinished()) { exit('All Done!'); } else { // send user to same page meta redirect // Layout MUST render the page. $batch->nextPage(); // or to use a header // header('location: ' . $batch->getAddress()); } ?> ``` -------------------------------- ### Module Configuration Variables Source: https://github.com/appstateess/canopy/blob/master/docs/Module_Development.txt Defines essential configuration variables for a module, such as name, version, import settings, and web addresses for updates. This example shows the boost.php configuration for the Blog module. ```php ``` -------------------------------- ### Locate FFmpeg Executable Source: https://github.com/appstateess/canopy/blob/master/docs/FFmpeg_and_Filecabinet.txt Use the 'whereis' command to find the installation path of the FFmpeg executable. This is necessary for configuring the FFmpeg directory in FileCabinet. ```bash whereis ffmpeg ``` -------------------------------- ### Get All Module Settings Source: https://github.com/appstateess/canopy/blob/master/docs/Settings_Class.txt Retrieve all current settings for a specific module as an associative array. This is useful for inspecting all configurations of a module at once. ```php $result = PHPWS_Settings::get('module_name'); ``` -------------------------------- ### Display PHP Information Source: https://github.com/appstateess/canopy/blob/master/setup/help/database.en_US.txt Create this file to check if your database support is compiled into your PHP installation. Search for your database name (e.g., mysql, pgsql) in the output. ```php ``` -------------------------------- ### Getting All Key Template Tags Source: https://github.com/appstateess/canopy/blob/master/docs/Key.txt Retrieve all key information as an associative array, suitable for use with PHPWS_Template::process. ```php $template = $key->getTplTags() $content = PHPWS_Template::process($template, 'my_mod', 'key_list.tpl'); ``` -------------------------------- ### Getting Key Creation Date Source: https://github.com/appstateess/canopy/blob/master/docs/Key.txt Retrieve the creation date of the key. A format string can be provided using strftime formatting. ```php $key->getCreateDate($format); ``` -------------------------------- ### Register Module with Key Source: https://github.com/appstateess/canopy/blob/master/docs/Key.txt Registers a module with the Key system, typically during installation. This allows for proper cleanup when a key is removed, ensuring related data in other modules is also handled. ```php Key::registerModule('module_title'); ``` -------------------------------- ### View All Available Icons Source: https://github.com/appstateess/canopy/blob/master/docs/Icon_class.txt Use the Icon::demo() method to quickly view all icons available in the system. This is helpful for discovering and selecting icons. ```php Icon::demo(); ``` -------------------------------- ### PHP Form Class Integration with Select Confirm Source: https://github.com/appstateess/canopy/blob/master/javascript/select_confirm/README.txt Example demonstrating how to integrate select_confirm with the PHPWS_Form class. It shows how to correctly set the 'select_id' when the form class prefixes element names. ```php $form = new PHPWS_Form('my_pets'); $form->addSelect('dogs', array('view'=>'View', 'delete'=>'Delete')); $tpl = $form->getTemplate(); $js_vars['value'] = 'Go'; $js_vars['select_id'] = 'my_pets_dogs'; $js_vars['action_match'] = 'delete'; $js_vars['message'] = 'Are you sure you wish to delete these dogs?'; $tpl['SUBMIT'] = javascript('select_confirm', $js_vars); ``` -------------------------------- ### Initialize and Instantiate Version Class Source: https://github.com/appstateess/canopy/blob/master/docs/Version.txt Require the Version class and instantiate it with your source table name. This is the first step to using the Version module. ```php PHPWS_Core::initModClass('version', 'Version.php'); $version = & new Version('source_table'); ``` -------------------------------- ### Initialize Control Panel Class Source: https://github.com/appstateess/canopy/blob/master/docs/ControlPanel.txt Require the Panel.php class using PHPWS_Core::initModClass before constructing a panel object. ```PHP PHPWS_Core::initModClass("controlpanel", "Panel.php"); ``` -------------------------------- ### Initialize Search Object Source: https://github.com/appstateess/canopy/blob/master/docs/Search.txt Create a new search object using the provided key ID. This is the first step in setting up search for your content. ```php $search = & new Search($key_id); ``` -------------------------------- ### Install Code Tag Plugin Source: https://github.com/appstateess/canopy/blob/master/javascript/ckeditor/plugins/codeTag/README.md To install the Code Tag plugin, place its files in the ckeditor/plugins/ directory and update your ckeditor/config.js file. ```javascript config.extraPlugins = 'codeTag'; ``` -------------------------------- ### Initialize Restore Class Source: https://github.com/appstateess/canopy/blob/master/docs/Version.txt Require the Restore class from the version module to enable restoration of backup versions. ```php PHPWS_Core::initModClass('version', 'Restore.php'); ``` -------------------------------- ### Initialize File Manager Source: https://github.com/appstateess/canopy/blob/master/docs/File_Manager.txt Include the Cabinet class and create a file manager object. The 'element_name' is the variable name for the file ID, and 'element_id' is the numeric ID of the current file. ```PHP PHPWS_Core::initModClass('filecabinet', 'Cabinet.php'); $manager = Cabinet::fileManager('element_name', $element_id); ``` -------------------------------- ### Getting the URL for a Key Source: https://github.com/appstateess/canopy/blob/master/docs/Key.txt Retrieve the URL for the item associated with the key. Pass TRUE to get a full URL including the site path. ```php $title = $key->getUrl(); ``` -------------------------------- ### Save Version Object Source: https://github.com/appstateess/canopy/blob/master/docs/Version.txt Instantiate a Version object, set its source and approval status, and then save it. ```php $version = & new Version('my_item_table'); $version->setSource($my_item); $version->setApproved($my_item->approved); $version->save(); ``` -------------------------------- ### Get Current Active Tab Source: https://github.com/appstateess/canopy/blob/master/docs/ControlPanel.txt Retrieve the identifier of the currently active tab using the getCurrentTab function, especially when the tab is not explicitly set in GET or REQUEST variables. ```PHP $current_tab = $panel->getCurrentTab(); ``` -------------------------------- ### Reset and Initialize Version Source: https://github.com/appstateess/canopy/blob/master/docs/Version.txt Reset the current version to a specific approval ID and then initialize it to load the item information. ```php $version->setId($approval_id); $version->init(); ``` -------------------------------- ### Getting a Single Form Element Source: https://github.com/appstateess/canopy/blob/master/docs/Forms.txt Retrieve the HTML output for a specific form element using the get function. Optionally, retrieve an array of elements, labels, and associated data. ```php $pet_text_field = $form->get('pet', [,FALSE]); ``` -------------------------------- ### Enabling Theme Execution Source: https://github.com/appstateess/canopy/blob/master/docs/Theme_Creation.txt Set LAYOUT_THEME_EXEC to "true" in config/layout/config.php to enable theme.php execution. ```php define('LAYOUT_THEME_EXEC', true); ``` -------------------------------- ### Using mktime to get UTC Unix timestamp Source: https://github.com/appstateess/canopy/blob/master/docs/Time.txt Use mktime to get a Unix timestamp based on UTC relative to your server's timezone. This is the recommended function for setting snapshot timestamps. ```PHP mktime(8, 0, 0, 8, 1, 2006); ``` -------------------------------- ### HTML Checkboxes Source: https://github.com/appstateess/canopy/blob/master/javascript/check_all/README.txt Example HTML structure for a group of checkboxes that can be controlled by the 'check_all' function. ```html Red Blue Yellow ``` -------------------------------- ### Clone Canopy Repository Source: https://github.com/appstateess/canopy/wiki/Installation-of-Canopy-for-ESS-Students Clone the Canopy repository to your local projects folder. Ensure you have Git installed. ```bash git clone https://github.com/AppStateESS/canopy.git ``` -------------------------------- ### Get Pager Data Source: https://github.com/appstateess/canopy/blob/master/docs/DB_Pager.txt Retrieves the data for the current page view from the pager. The content is then added to the layout. ```php $content = $pager->get(); Layout::add($content); ``` -------------------------------- ### Getting the Current Flagged Key Source: https://github.com/appstateess/canopy/blob/master/docs/Key.txt Retrieve the currently flagged key. If no key is flagged, this will return NULL. ```php $key = Key::getCurrent(); ``` -------------------------------- ### Create Restore Object Source: https://github.com/appstateess/canopy/blob/master/docs/Version.txt Instantiate a Version_Restore object with module name, table name, module ID, and item class for restoring backups. ```php $restore = & new Version_Restore('my_mod', 'my_mod_table', $my_mod->id, 'my_mod_class', ``` -------------------------------- ### Flagging a Key Source: https://github.com/appstateess/canopy/blob/master/docs/Key.txt Construct and flag a key to make it active for other modules. This is a simple two-step process. ```php $key = & Key($key_id); $key->flag(); ``` -------------------------------- ### Get File Association Object Source: https://github.com/appstateess/canopy/blob/master/docs/File_Manager.txt Retrieve the File_Assoc object for a given file ID to access its methods and properties. ```PHP $file = Cabinet::getFile($file_id); ``` -------------------------------- ### Creating Translation Files with xgettext Source: https://github.com/appstateess/canopy/blob/master/docs/Language.txt Use the xgettext command-line utility to generate a .po translation file from your source code. You can specify individual files, all files in a directory, or a list of files. ```bash xgettext testing.php ``` ```bash xgettext *.php ``` ```bash grep -lr --include='*.php' 'gettext' * > translate_list.txt ``` ```bash xgettext -s --no-location --language=PHP -f translate_list.txt ``` -------------------------------- ### Disable Weekends on Generate Source: https://github.com/appstateess/canopy/blob/master/javascript/datetimepicker/index.html Disables all weekend days when the DateTimePicker is generated. This example uses the 'onGenerate' event to modify the calendar. ```javascript $('#datetimepicker8').datetimepicker({ onGenerate:function( ct ){ $(this).find('.xdsoft_date') .toggleClass('xdsoft_disabled'); }, minDate:'-1970/01/2', maxDate:'+1970/01/2', timepicker:false }); ``` -------------------------------- ### Group WHERE Conditions Source: https://github.com/appstateess/canopy/blob/master/docs/Database_Class.txt Demonstrates grouping of WHERE conditions to control the order of evaluation. This example combines an ID range with a name condition. ```php $db->addWhere('id', 3, '>'); ``` ```php $db->addWhere('name', 'L', 'LIKE', 'or', 1); ``` -------------------------------- ### Display a Basic Icon Source: https://github.com/appstateess/canopy/blob/master/docs/Icon_class.txt Use the Icon::show() method to display a basic icon. The method returns an HTML string representing the icon. ```php $edit_icon = Icon::show('edit'); echo $edit_icon; ``` -------------------------------- ### Get Table Columns Source: https://github.com/appstateess/canopy/blob/master/docs/Database_Class.txt Retrieve a list of all column names in the current table using getTableColumns. The result is returned as an array. ```php $result = $db->getTableColumns(); ``` -------------------------------- ### Get Last Executed Query Source: https://github.com/appstateess/canopy/blob/master/docs/Database_Class.txt Returns the SQL string of the most recently executed query sent to the PEAR database object. ```php PHPWS_DB::lastQuery() ``` -------------------------------- ### Get URL Parameter Function Source: https://github.com/appstateess/canopy/blob/master/javascript/ckeditor/plugins/wsc/dialogs/ciframe.html Parses and returns the value of a specified URL parameter from the current window's location. ```javascript function gup( name ) { name = name.replace( /\\\[\\\\\]/, '\\\\[' ).replace( /\\\\]/, '\\\\\]' ) ; var regexS = '[[\\?&]]' + name + '=( F[^&#]*)' ; var regex = new RegExp( regexS ) ; var results = regex.exec( window.location.href ) ; if ( results ) return results[ 1 ] ; else return '' ; } ``` -------------------------------- ### Include Editor Class Source: https://github.com/appstateess/canopy/blob/master/docs/Editor.txt Include the Editor class using PHPWS_Core::initCoreClass or require_once. ```php PHPWS_Core::initCoreClass('Editor.php'); ``` ```php require_once PHPWS_SOURCE_DIR . 'core/class/Editor.php'; ``` -------------------------------- ### Instantiate Control Panel Object Source: https://github.com/appstateess/canopy/blob/master/docs/ControlPanel.txt Create a new Panel object, providing a unique 'panel name' to distinguish it from other panels within the module. ```PHP $panel = & new PHPWS_Panel("myModPanel"); ``` -------------------------------- ### Template Structure for Nested Repeats Source: https://github.com/appstateess/canopy/blob/master/docs/template.txt An example template structure demonstrating nested repeating rows, with an outer 'lastname-list' and an inner 'firstname-list'. ```HTML
  1. {LAST_NAME}
    1. {FIRST_NAME}
``` -------------------------------- ### Joining tables and adding conditions Source: https://github.com/appstateess/canopy/blob/master/docs/Database_Class.txt Demonstrates how to join tables and add WHERE conditions that reference columns from different tables. The table name must be specified when adding WHERE clauses for joined tables. ```PHP $db = & new PHPWS_DB('table1'); $db->addColumn('lastname'); $db->addWhere('firstname', 'Ted'); // notice I put the table name in the column parameter $db->addWhere('table2.age', '30', '>'); $db->addWhere('table2.id', 'table1.id'); $result = $db->select(); SELECT table1.lastname FROM table1, table2 WHERE ( table1.firstname = 'ted' AND table2.age > '30' AND table2.id = table1.id ) ``` -------------------------------- ### Stand-alone Function for Report Row Source: https://github.com/appstateess/canopy/blob/master/docs/DB_Pager.txt Example of a stand-alone function that returns an associative array for a report row. It accepts data as an argument. ```php function report_row_function($data) { $row['name'] = $data['name'] $row['date_of_entry'] = strftime('%c', $data['date_of_entry']); return $row; } ``` -------------------------------- ### Compile .po file to .mo file Source: https://github.com/appstateess/canopy/blob/master/docs/Language.txt Use the msgfmt command to compile a .po file into a binary .mo file, which is used by gettext applications. ```bash msgfmt messages.po ``` -------------------------------- ### Block Module SmartTag with Different Function and ID Source: https://github.com/appstateess/canopy/blob/master/docs/SmartTags.txt Example of a SmartTag for the 'block' module calling the 'hide' function with an ID of '3'. ```text [block:hide:3] ``` -------------------------------- ### Create and Save a Key Object Source: https://github.com/appstateess/canopy/blob/master/docs/Key.txt This function demonstrates how to create a new Key object or load an existing one based on its ID. It then sets various properties of the key, such as module, item name, item ID, URL, title, and summary, before saving it. This is typically done when saving a content item within a module. ```php function saveKey() { // If the key_id on my item has not been set, I create // a new key object if (empty($this->key_id)) { $key = & new Key; } else { // My key_id is set, so I am going to construct my key // using this id. $key = & new Key($this->key_id); // if there is a problem pulling the key, the _error // variable will contain the problem if (PEAR::isError($key->_error)) { $key = & new Key; } } // Now I set the various variables corresponding to my content // item. $key->setModule('blog'); // the module I am in // a module may have multiple content items. We therefore set an // item name for the item. If we don't set the item name, the Key // class sets the module title as the item name. $key->setItemName('entry'); // Again, we set the item's id when we create the key. This is why // you save the item before creating the key. $key->setItemId($this->id); // I will explain why this is important later $key->setEditPermission('edit_blog'); // the getViewLink function in blog just returns the url address // to the view function. Note that if you have mod_rewrite enabled // (and plan on leaving it enabled), it is perfectly ok to send // the shortened version of the link $key->setUrl($this->getViewLink(TRUE)); // Note that the title will be stripped of ALL tags. HTML formatting // the title is not allowed for reasons that will be apparent later $key->setTitle($this->title); // The summary setting removes tags as well, including tags // converted after PHPWS_Text::parseInput $key->setSummary($this->entry); // Now we call the save function $key->save(); // if the save went fine, it now has an id. Blog puts the id // into its settings and returns the key object $this->key_id = $key->id; return $key; } ``` -------------------------------- ### Initialize DateTimePicker by Class Source: https://github.com/appstateess/canopy/blob/master/javascript/datetimepicker/index.html Initializes the DateTimePicker for all elements with the class 'some_class'. ```javascript $('.some_class').datetimepicker(); ``` -------------------------------- ### Setting Form Submission Method Source: https://github.com/appstateess/canopy/blob/master/docs/Forms.txt Change the HTTP method used for form submission between 'post' and 'get' using the setMethod function. ```php $form->setMethod('get'); to change back: $form->setMethod('post'); ``` -------------------------------- ### Define Module Permissions Source: https://github.com/appstateess/canopy/blob/master/docs/Module_Development.txt This snippet shows how to define basic module permissions. Set `$user_permissions = true;` if you only need all-or-nothing permissions. ```php $user_permissions = true; ``` -------------------------------- ### Get Unapproved Versions Source: https://github.com/appstateess/canopy/blob/master/docs/Version.txt Retrieve an array of unapproved versions based on the configured approval object. Returns NULL if no results are found. ```php $subversions = $approval->get(); ``` -------------------------------- ### Get Table Node Name Source: https://github.com/appstateess/canopy/blob/master/lib/pear/HTML/Template/Flexy/templates/translator.html Helper function to construct a node name based on input. Used internally by visibility functions. ```javascript function getTableNodeName(Node){ return "pane" + Node; } ``` -------------------------------- ### Create Symbolic Link for Magic Database Source: https://github.com/appstateess/canopy/blob/master/docs/Installing_FileInfo.txt Creates a symbolic link for the magic mime database, as the error message indicates a missing 'magic' file, but 'magic.mime' is actually required. ```bash sudo ln -s /usr/share/file/magic magic.mime ``` -------------------------------- ### Set Restore and Remove URLs for Version Module Source: https://github.com/appstateess/canopy/blob/master/docs/Version.txt Set the URLs for restoring and removing a version. These are optional parameters for the Version module. ```php $restore->setRestoreUrl($restore_link); // This is the url to our module that will restore the version $restore->setRemoveUrl($remove_link); // This is the url to our module that will remove one of the old // versions ``` -------------------------------- ### Getting Key Update Date Source: https://github.com/appstateess/canopy/blob/master/docs/Key.txt Retrieve the last update date of the key. A format string can be provided using strftime formatting. ```php $key->getUpdateDate($format); ``` -------------------------------- ### Load Version Data into an Object Source: https://github.com/appstateess/canopy/blob/master/docs/Version.txt Load the version's item information into a provided object instance. ```php $my_item = & new My_Item; $version->loadObject($my_item); ``` -------------------------------- ### Adjust Folder Permissions Source: https://github.com/appstateess/canopy/wiki/Installation-of-Canopy-for-ESS-Students Adjust permissions for folders within your Canopy directory to 755. This may be necessary after initial setup or configuration. ```bash chmod 755 ``` -------------------------------- ### Control Panel Tab Definition Source: https://github.com/appstateess/canopy/blob/master/docs/Module_Development.txt Example of how to define a tab for a module within the Control Panel. This snippet defines the 'My Page' tab. ```php $tabs[] = array('title' => _('My Page'), 'label' => 'my_page', 'link' => 'index.php?module=users&action=user', ); ``` -------------------------------- ### Setting the Limit for Query Results Source: https://github.com/appstateess/canopy/blob/master/docs/Database_Class.txt Use setLimit to control the maximum number of rows returned by a query. This example limits results to 2. ```php $db->setLimit(2); ``` -------------------------------- ### Check Editor Compatibility Source: https://github.com/appstateess/canopy/blob/master/docs/Editor.txt Verify if the user's browser is compatible and the editor is enabled by the administrator. ```php if (!Editor::willWork()) { echo plainOleTextArea(); } ``` -------------------------------- ### Get Posted Date Value Source: https://github.com/appstateess/canopy/blob/master/docs/Forms.txt Retrieves the Unix timestamp for a posted date from a form element. Assumes the 'event_date' form element was submitted. ```PHP $unix_time = PHPWS_Form::getPostedDate('event_date'); ``` -------------------------------- ### Check if File is an Image and Get Source Source: https://github.com/appstateess/canopy/blob/master/docs/File_Manager.txt Checks if a file is an image and retrieves its source. Pass FALSE to isImage() to exclude resized images. ```php if ($file->isImage()) { $image = $file->getSource(); echo 'The file name of this image is ' . $image->file_name; } ```