Example #1
0
 /**
  * AJAX callback to fetch examples
  */
 public static function getExampleFile()
 {
     global $civicrm_root;
     $basePath = CRM_Utils_file::addTrailingSlash($civicrm_root, '/');
     if (!empty($_GET['entity']) && strpos($_GET['entity'], '.') === FALSE) {
         $examples = array();
         foreach (scandir($basePath . 'api/v3/examples/' . $_GET['entity']) as $item) {
             $item = str_replace('.php', '', $item);
             if ($item && strpos($item, '.') === FALSE) {
                 $examples[] = array('key' => $item, 'value' => $item);
             }
         }
         CRM_Utils_JSON::output($examples);
     }
     if (!empty($_GET['file']) && strpos($_GET['file'], '.') === FALSE) {
         $fileName = $basePath . 'api/v3/examples/' . $_GET['file'] . '.php';
         if (file_exists($fileName)) {
             echo file_get_contents($fileName);
         } else {
             echo "Not found.";
         }
         CRM_Utils_System::civiExit();
     }
     CRM_Utils_System::permissionDenied();
 }
 /**
  * Get available CKEditor plugin list.
  *
  * @return array
  */
 private function getCKPlugins()
 {
     $plugins = array();
     $pluginDir = Civi::paths()->getPath('[civicrm.root]/bower_components/ckeditor/plugins');
     foreach (glob($pluginDir . '/*', GLOB_ONLYDIR) as $dir) {
         $dir = rtrim(str_replace('\\', '/', $dir), '/');
         $name = substr($dir, strrpos($dir, '/') + 1);
         $dir = CRM_Utils_file::addTrailingSlash($dir, '/');
         if (is_file($dir . 'plugin.js')) {
             $plugins[$name] = array('id' => $name, 'text' => ucfirst($name), 'icon' => NULL);
             if (is_dir($dir . "icons")) {
                 if (is_file($dir . "icons/{$name}.png")) {
                     $plugins[$name]['icon'] = "bower_components/ckeditor/plugins/{$name}/icons/{$name}.png";
                 } elseif (glob($dir . "icons/*.png")) {
                     $icon = CRM_Utils_Array::first(glob($dir . "icons/*.png"));
                     $icon = rtrim(str_replace('\\', '/', $icon), '/');
                     $plugins[$name]['icon'] = "bower_components/ckeditor/plugins/{$name}/icons/" . substr($icon, strrpos($icon, '/') + 1);
                 }
             }
         }
     }
     return $plugins;
 }
Example #3
0
 /**
  * @param bool $checkIfFileExists
  *   If false, this fn will return fileName even if it doesn't exist
  *
  * @return null|string
  */
 public static function getConfigFile($checkIfFileExists = TRUE)
 {
     // FIXME: Basing file path off imageUploadDir sucks, but it's all we got
     $dir = CRM_Core_Config::singleton()->imageUploadDir;
     $dir = CRM_Utils_file::addTrailingSlash(str_replace('\\', '/', $dir), '/');
     $dir = str_replace('/persist/contribute/', '/persist/', $dir);
     $fileName = $dir . self::CONFIG_FILENAME;
     return !$checkIfFileExists || is_file($fileName) ? $fileName : NULL;
 }